from functools import lru_cache

from pydantic_settings import BaseSettings, SettingsConfigDict

from app import ENV_PATH, ENV_PROD_PATH
from config.settings import ENV

_env_path = ENV_PATH if ENV == "dev" else ENV_PROD_PATH


class Conf(BaseSettings):
    """配置"""
    # +++++++++ 初始中配置 +++++++++
    DEBUG: bool = False
    BASEURL: str = "127.0.0.1:8000"
    # 日志目录
    LOG_DIR: str = None
    # mysql配置
    MYSQL_CONFIG: dict = None
    # redis配置
    REDIS_HOST: str = None
    REDIS_PORT: int = None
    REDIS_DB: int = None
    # snowflake配置
    SNOW_WORKER_ID: int = None
    SNOW_DATACENTER_ID: int = None

    # +++++++++ 生产环境配置 +++++++++
    model_config = SettingsConfigDict(env_file=_env_path, env_file_encoding="utf-8")


@lru_cache()
def init_conf() -> Conf:
    return Conf()
